<template>
  <div class="wrapper" ref="wrapper">
    <div class="content">
      <slot></slot>
    </div>
  </div>
</template>

<script>
import BScroll from "better-scroll";
export default {
  name: "Scroll",
  props:{
    probeType:{
      type: Number,
      default: 0
    },
    pullUpLoad:{
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      scroll: null,
    };
  },
  methods: {
    scrollTo(x,y,time=300){
     this.scroll && this.scroll.scrollTo && this.scroll.scrollTo(x,y,time)
    },
    scrollFinished(){
      this.scroll && this.scroll.finishPullUp && this.scroll.finishPullUp()
    },
    scrollRefresh(){
      console.log('============')
      this.scroll && this.scroll.refresh && this.scroll.refresh()
    },
    getScrollY (){
      return this.scroll ? this.scroll.y : 0;
    }
  },
  mounted() {
    // this.$nextTick(() => {
    //   let bs = new BScroll(this.$refs.wrapper, {
    //     click: true,
    //   });
    // });
    // 默认情况下Bscroll时不可以实时的监听滚动的位置
    // probeType属性：侦测
    // 参数
    // 0 ,1 都是不侦测实时的位置
    // 2： 在手指滚动的过程中侦测，手指离开后的惯性滚动不侦测
    // 3：只要是滚动，都侦测
    // click属性
    // this.scroll = new BScroll(this.$refs.wrapper,{
    //   })
    let that = this;
    // 1.创建BScroll对象
    this.scroll = new BScroll(this.$refs.wrapper, {
      click: true,
      probeType: this.probeType,
      pullUpLoad: this.pullUpLoad,
      useTransition: false,

    });
    if(this.probeType == 2 || this.probeType == 3){
      this.scroll.on('scroll',(position) => {
      this.$emit('scroll', position)
    })
    }
    if(this.pullUpLoad){
      this.scroll.on('pullingUp',() => {
      this.$emit('pullingUp')
    })
    }
    this.scroll && this.scroll.scrollTo && this.scroll.scrollTo(0,0)

  },
};
</script>

<style scoped>
.content {
  /* height: 12594px */
  /* padding-bottom: 15px; */
  box-sizing: border-box;
}
</style>